<?php
defined ( 'BASEPATH' ) or exit ( 'No direct script access allowed' );
class Project_content_comment extends CI_Controller{
	public function __construct() {
		parent::__construct ();
		$this->load->model("user_model");
		$this->load->model("project_content_comment_model");
		$this->load->model('category_model');
		$whereArr = array("status"=>1);
		$this->category_list = $this->category_model->resultAll($whereArr);
	}
	/*
	 *加载品论页面 
	 */
	public function add($pcid=1){
		$this->tologin->isLogin ( site_url ( 'login' ) );
		$data['pcid'] = $pcid;
		$data['category_list'] = $this->category_list;
		$this->load->view('project_content_comment_add',$data);
	}
	/*
	 *处理提交的数据 
	 */
	public function do_add(){
		$content = $this->input->post("content");
		if(empty($content)){
			$data['message'] = "内容不能为空!!";
			$this->load->view("assists/error",$data);
		}else{
			$data['uid'] = $this->change_user_id($this->session->userdata('username'));
			$data['pcid'] = $this->input->post('pcid')+0;
			$data['createtime'] = time();
			$data['content'] = $this->input->post('content');
			$result = $this->project_content_comment_model->insert($data);
			if($result){
				$dataArr['url'] = site_url('Project_content/project_content_detail/'.$data['pcid']);
				$dataArr['message'] = "评论成功!!";
				$this->load->view("assists/success",$dataArr);
			}else{
				$dataArr['message'] = "评论失败!!";
				$this->load->view("assists/error",$dataArr);
			}
		}
	}
	/*
	 *把用户名转换为用户id 
	 */
	public function change_user_id($username){
		$whereArr = array('username'=>$username);
		$user = $this->user_model->row($whereArr);
		if($user){
			return $user['uid'];
		}
	}
}